<?php

class init{
public function index()
{
$cur_city_id = intval($GLOBALS['request']['cur_city_id']);
if ($cur_city_id == 0){
$deal_city = get_current_deal_city();
$cur_city_id = $deal_city['id'];
$city_name = $deal_city['name'];
}
else
{
$city_name = $GLOBALS['db']->getOne('select name from '.DB_PREFIX.'deal_city where id = '.$cur_city_id);
}
$root = array();
$root['return'] = 1;
$root['city_id'] = $cur_city_id;
$root['city_name'] = $city_name;
$root['catalog_id'] = intval($GLOBALS['m_config']['catalog_id']);
$root['catalog_id_name'] = $GLOBALS['m_config']['catalog_id_name'];
$root['shop_cate_id'] = intval($GLOBALS['m_config']['shop_cate_id']);
$root['shop_cate_id_name'] = $GLOBALS['m_config']['shop_cate_id_name'];
$root['event_cate_id'] = intval($GLOBALS['m_config']['event_cate_id']);
$root['event_cate_id_name'] = $GLOBALS['m_config']['event_cate_id_name'];
$root['price_type']=price_type();
if(strim($GLOBALS['m_config']['sina_app_key'])!=''&&strim($GLOBALS['m_config']['sina_app_secret'])!='')
{
$root['api_sina'] = 1;
$root['sina_app_key'] = $GLOBALS['m_config']['sina_app_key'];
$root['sina_app_secret'] = $GLOBALS['m_config']['sina_app_secret'];
$root['sina_bind_url'] = $GLOBALS['m_config']['sina_bind_url'];
}
if(strim($GLOBALS['m_config']['tencent_app_key'])!=''&&strim($GLOBALS['m_config']['tencent_app_secret'])!='')
{
$root['api_tencent'] = 1;
$root['tencent_app_key'] = $GLOBALS['m_config']['tencent_app_key'];
$root['tencent_app_secret'] = $GLOBALS['m_config']['tencent_app_secret'];
$root['tencent_bind_url'] = $GLOBALS['m_config']['tencent_bind_url'];
}
$root['menu']=array();
$root['menu']=  $GLOBALS['db']->getAll('SELECT distinct  ctl.cate_id,dc.name FROM '.DB_PREFIX.'deal_cate_type_city_link as ctl left join '.DB_PREFIX.'deal_cate as dc on ctl.cate_id=dc.id   ');
foreach($root['menu'] as $ck=>$cv)
{
$root['menu'][$ck]['child']=$GLOBALS['db']->getAll('SELECT  distinct ctl.cate_type_id, dct.name FROM '.DB_PREFIX.'deal_cate_type_city_link as ctl left join  '.DB_PREFIX."deal_cate_type as dct on ctl.cate_type_id=dct.id  WHERE ctl.cate_id='{$cv['cate_id']}' ");
}
$fuckk = Array
(
'cate_id'=>0,
'name'=>'全部分类',
'child'=>Array
(
0 =>Array
(
'cate_type_id'=>0,
'name'=>'全部分类'
)
)
);
array_unshift($root['menu'],$fuckk);
$root['citylist'] = getCityArray();
$root['region_version'] = intval($GLOBALS['m_config']['region_version']);
$root['only_one_delivery'] = intval($GLOBALS['m_config']['only_one_delivery']);
$root['kf_phone'] = $GLOBALS['m_config']['kf_phone'];
$root['kf_email'] = $GLOBALS['m_config']['kf_email'];
$root['about_info'] = $GLOBALS['m_config']['about_info'];
$root['version'] = VERSION;
$root['page_size'] = PAGE_SIZE;
$root['has_region'] = intval($GLOBALS['m_config']['has_region']);
$root['newslist'] = $GLOBALS['m_config']['newslist'];
$root['program_title'] = $GLOBALS['m_config']['program_title'];
$root['addr_tlist'] = $GLOBALS['m_config']['addr_tlist'];
$root['quanlist'] = getQuanArray($cur_city_id);
$root['deal_cate_list'] = getDealCateArray();
$root['index_logo'] = get_abs_img_root($GLOBALS['m_config']['index_logo']);
output($root);
}
}
function price_type()
{
$price=array();
$price['1']='50元以下';
$price['2']='101-200';
$price['3']='201-400';
$price['4']='400以上';
return $price;
}
function getCityArray(){
$sql = 'select id, name, pid, uname as py, null as image, 0 as has_child from '.DB_PREFIX.'deal_city where is_delete = 0 and is_effect = 1 order by sort desc ';
$list = $GLOBALS['db']->getAll($sql);
return $list;
}
function getCatalogArray(){
$tree_list = $GLOBALS['cache']->get('m_CATELIST');
if($tree_list===false)
{
$sql = 'select id,name,pid,uname as py,icon from '.DB_PREFIX.'deal_cate';
$list = $GLOBALS['db']->getAll($sql);
foreach($list as $k=>$v)
{
$count = intval($GLOBALS['db']->getOne('select count(*) from '.DB_PREFIX.'deal_cate where pid = '.$v['id']));
if($count>0)
$list[$k]['has_child'] = 1;
else
$list[$k]['has_child'] = 0;
}
$tree_list = m_toTree($list,'id','pid','child');
$GLOBALS['cache']->set('m_CATELIST',$tree_list);
}
return $tree_list;
}
function getCatalogArraySearch(){
$list = $GLOBALS['cache']->get('m_CATELISTSEARCH');
if($list === false)
{
$sql = 'select id,name,pid,uname as py,icon from '.DB_PREFIX.'deal_cate';
$list = $GLOBALS['db']->getAll($sql);
foreach($list as $k=>$v)
{
$count = intval($GLOBALS['db']->getOne('select count(*) from '.DB_PREFIX.'deal_cate where pid = '.$v['id']));
if($count>0)
{
$list[$k]['has_child'] = 1;
$child = new m_child('deal_cate');
$ids = $child->getChildIds($v['id'],$pk_str='id',$pid_str ='pid');
$ids[] = 0;
$child_list = $GLOBALS['db']->getAll( 'select id,name,pid,uname as py  from '.DB_PREFIX.'deal_cate where id in ('.implode(',',$ids).')');
foreach($child_list as $kk=>$vv)
{
$count = intval($GLOBALS['db']->getOne('select count(*) from '.DB_PREFIX.'deal_cate where pid = '.$vv['id']));
if($count>0)
$child_list[$kk]['has_child'] = 1;
else
$child_list[$kk]['has_child'] = 0;
}
$list[$k]['child'] = m_toTree($child_list,'id','pid','child');
}
else
$list[$k]['has_child'] = 0;
}
$GLOBALS['cache']->set('m_CATELISTSEARCH',$list);
}
return $list;
}
function getThirdLogin()
{
$result['sina']['sina_app_key'] = $GLOBALS['db']->getRow('select code,val from '.DB_PREFIX."m_config where code ='sina_app_key' ");
$result['sina']['sina_app_secret']  = $GLOBALS['db']->getRow('select code,val from '.DB_PREFIX."m_config where code ='sina_app_secret' ");
$result['sina']['sina_redirect_uri'] = $GLOBALS['db']->getRow('select code,val from '.DB_PREFIX."m_config where code ='sina_redirect_uri' ");
$result['tqq']['tqq_app_key'] = $GLOBALS['db']->getRow('select code,val from '.DB_PREFIX."m_config where code ='tqq_app_key' ");
$result['tqq']['tqq_app_secret']  = $GLOBALS['db']->getRow('select code,val from '.DB_PREFIX."m_config where code ='tqq_app_secret' ");
$result['tqq']['tqq_redirect_uri'] = $GLOBALS['db']->getRow('select code,val from '.DB_PREFIX."m_config where code ='tqq_redirect_uri' ");
$data=array();
$snum=0;
foreach($result['sina'] as $skey=>$svalue)
{
$data[$svalue['code']]=$svalue['val'];
if(empty($data[$svalue['code']])){
$snum=$snum+1;
}
}
$snum>0?$data['sina_status']=0:$data['sina_status']=1;
$tnum=0;
foreach($result['tqq'] as $tkey=>$tvalue)
{
$data[$tvalue['code']]=$tvalue['val'];
if(empty($data[$tvalue['code']])){
$tnum=$tnum+1;
}
}
$tnum>0?$data['tqq_status']=0:$data['tqq_status']=1;
return $data;
}
function getQuanArray($city_id){
$sql = 'select id, name from '.DB_PREFIX.'area where pid = 0 and city_id = '.intval($city_id).' order by sort desc ';
$list = $GLOBALS['db']->getAll($sql);
return $list;
}
function getDealCateArray(){
$sql = 'select id, pid, name, icon from '.DB_PREFIX.'deal_cate where pid = 0 and is_effect = 1 and is_delete = 0 order by sort desc ';
$list = $GLOBALS['db']->getAll($sql);
return $list;
}

?>